#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main()
{
    int t = 0;
    scanf("%d", &t);
    while(t--)
    {
        int n = 0;
        scanf("%d", &n);
        char str[n + 1];
        scanf("%s", str);

        int record[n + 1];
        int k = n;
        for(k = n; k >= 1; k--)
        {
            int begin = 0;
            memset(record, 0, sizeof(record));
            int flag = 1;

            int i = begin;
            while(flag)
            {
                flag = 0;
                for(i = begin; i < n; i++)
                {
                    if(record[i] % 2 == 1 && str[i] == '1'||record[i] % 2 == 0 && str[i] == '0')
                    {
                        flag = 1;
                        begin = i;
                        break;
                    }
                }

                if(begin + k - 1 > n - 1)
                {
                    break;
                }

                for(int i = begin; i < begin + k; i++)
                {
                    record[i]++;
                }
            }

            if(flag == 0)
            {
                printf("%d\n", k);
                break;
            }
        }
    }
    return 0;
}